define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'aliyun_oss/index' + location.search,
                    add_url: 'aliyun_oss/add',
                    edit_url: 'aliyun_oss/edit',
                    del_url: 'aliyun_oss/del',
                    multi_url: 'aliyun_oss/multi',
                    import_url: 'aliyun_oss/import',
                    table: 'aliyun_oss',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'accessKeyId', title: __('AccessKeyId'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'accessKeySecret', title: __('AccessKeySecret'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'bucket', title: __('Bucket'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'endpoint', title: __('Endpoint'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'cdnurl', title: __('Cdnurl'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'uploadmode', title: __('Uploadmode'), searchList: {"client":__('Uploadmode client'),"server":__('Uploadmode server')}, formatter: Table.api.formatter.normal},
                        {field: 'serverbackupdata', title: __('Serverbackupdata'), searchList: {"1":__('Serverbackupdata 1'),"0":__('Serverbackupdata 0')}, formatter: Table.api.formatter.normal},
                        {field: 'savekey', title: __('Savekey'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'expire', title: __('Expire'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'maxsize', title: __('Maxsize'), operate:'BETWEEN'},
                        {field: 'mimetype', title: __('Mimetype'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'multipledata', title: __('Multipledata'), searchList: {"1":__('Multipledata 1'),"0":__('Multipledata 0')}, formatter: Table.api.formatter.normal},
                        {field: 'thumbstyle', title: __('Thumbstyle'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'chunkingdata', title: __('Chunkingdata'), searchList: {"1":__('Chunkingdata 1'),"0":__('Chunkingdata 0')}, formatter: Table.api.formatter.normal},
                        {field: 'chunksize', title: __('Chunksize'), operate:'BETWEEN'},
                        {field: 'syncdeletedata', title: __('Syncdeletedata'), searchList: {"1":__('Syncdeletedata 1'),"0":__('Syncdeletedata 0')}, formatter: Table.api.formatter.normal},
                        {field: 'apiuploaddata', title: __('Apiuploaddata'), searchList: {"1":__('Apiuploaddata 1'),"0":__('Apiuploaddata 0')}, formatter: Table.api.formatter.normal},
                        {field: 'noneedlogindata', title: __('Noneedlogindata'), searchList: {"api":__('Noneedlogindata api'),"index":__('Noneedlogindata index'),"admin":__('Noneedlogindata admin')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
